﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
/*
 * 
 * 本例中 FrameDebugger截图，demo01_1_image01
 * CameraEvent设置为AfterForwardOpaque,Clear操作放在渲染green之前
 * 
 * 画面为,先渲染了红色cube,然后调用了Clear变成了黑色,最后渲染了green.
 * 
 * 可以看出来Clear操作被提前了,CommandBuffer的指令也被延后了. 
 * 
 * 
 */
namespace Example02_Demo01_1
{
	public class Demo01_1 : MonoBehaviour
	{
		CommandBuffer m_commandBuffer;
		public Material mat_green;
		public GameObject redCube;

		private void OnEnable()
		{
			m_commandBuffer = new CommandBuffer();
			m_commandBuffer.name = "GreenCube";

			Renderer _renderer = redCube.GetComponent<Renderer>();

			//1.
			m_commandBuffer.ClearRenderTarget(true, true, Color.black);

			//2.
			m_commandBuffer.DrawRenderer(_renderer, mat_green);

			//3.
			Camera.main.AddCommandBuffer(CameraEvent.AfterForwardOpaque, m_commandBuffer);

		}
	}
}
